/**
 * 程序运行周期中的数据库对象
 */
package net.youpo.Market.db;

import net.youpo.Market.MarketApplication;
import android.database.sqlite.SQLiteDatabase;

public class MarketDatabase {
	private static SQLiteDatabase mDatabase;
	private static DatabaseHelper dh;

	public static DatabaseHelper getMarketDH() {
		if (dh == null) {
			dh = new DatabaseHelper(MarketApplication.getMarketAppContext(),
					"market.db", null, 1);
		}
		return dh;
	}

	/**
	 * 获得数据库对象
	 * 
	 * @return
	 */
	public static SQLiteDatabase getMarketDB() {
		if (mDatabase == null || !mDatabase.isOpen()) {
			dh = new DatabaseHelper(MarketApplication.getMarketAppContext(),
					"market.db", null, 1);
			mDatabase = dh.getWritableDatabase();
		}
		return mDatabase;
	}

	/**
	 * 关闭数据库
	 */
	public static void closeMarketDB() {
		if (mDatabase != null) {
			mDatabase.close();
		}
	}
}
